package com.xkcoding.orm.jdbctemplate.Clickhousejdbctemplate.common.jdbcTemplate;

import com.xkcoding.orm.jdbctemplate.Clickhousejdbctemplate.common.utils.TranslatorUtils;
import lombok.extern.log4j.Log4j2;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.util.List;

/**
 * Cilckhouse 专用
 */
@Log4j2
public class CilckhouseDataWorker extends JdbcTemplate implements DataWorker {

    public CilckhouseDataWorker(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    public <T> void saveAll(List<T> arry) {
        String sql = FindFactory.saveSql(arry.get(0).getClass());
        log.info("#################jdbcTemplate批量保存########################");
        log.info(sql);
        BatchPreparedStatementSetter batchPreparedStatementSetter = TranslatorUtils.saveBatchPreparedStatementSetter(arry);
        super.batchUpdate(sql, batchPreparedStatementSetter);
    }
}
